package org.example.shop.consumer;

import lombok.extern.slf4j.Slf4j;
import org.example.shop.config.RabbitMQConfig;
import org.example.shop.service.MailService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component // 1.让spring管理类
@RabbitListener(queues = RabbitMQConfig.RABBITMQ_DEFAULT_TOPIC) // 2.设置要订阅的主题
@Slf4j
public class RabbitMessageConsumer {
    @Resource
    private MailService mailService;

    // 3.绑定处理 队列中的消息来了后 的处理方法
    // 注意： 方法的参数 发送的数据类型和此处的参数类型要一致
    @RabbitHandler
    public void process(Map<String, String> map) {
        log.info("获取到一条消息:" + map.toString());
        // 需要发送验证邮件
        boolean b = mailService.sendVerifyEmail(map.get("email"), map.get("token"));
        log.info("发送验证邮件成功了?" + b);
    }
}
